package logic

import (
	"cart_srv/models/redis"
	"context"
	"errors"
	"fmt"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartListLogic {
	return &CartListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartListLogic) CartList(in *cart.CartListRequest) (*cart.CartListResponse, error) {
	// todo: add your logic here and delete this line

	list, c, amount, err := redis.CartList(int(in.UserId))
	if err != nil {
		return nil, errors.New("购物车列表展示失败")
	}
	fmt.Println("购物车列表展示成功")

	return &cart.CartListResponse{List: list, Count: int32(c), Amount: float32(amount)}, nil
}
